#ifndef __DOUBLECIRCLELINKLIST_H_
#define __DOUBLECIRCLELINKLIST_H_

#include <stdbool.h>

#define ElementType void*

typedef struct DCNode
{
    ElementType data; //存储的数据
    struct DCNode* prev;//前继节点
    struct DCNode* next;//后继节点 
}DCNode;

typedef struct DoubleCircleLinkListPrivate
{
    struct DCNode* head;//头指针，无头结点
    struct DCNode* tail;//尾指针，无头结点
    int len;          //有效节点个数
}DCList;

//链表节点打印回调函数
typedef void (*PrintCall)(ElementType data);
//销毁链表节点data域回调函数
typedef void (*DataDestroy)(ElementType data);
//节点数据比较回调函数
typedef int (*DataCompare)(ElementType ctx, ElementType data);

class DoubleCircleLinkList
{
private:
    DCList* list;

public:
    //初始化
    DoubleCircleLinkList();
    //初始化，返回指针
    DCList* DCList_Creat();
    //销毁双向循环链表
    ~DoubleCircleLinkList();
    //遍历,自定义打印回调函数
    void DCList_Travel(PrintCall printCall);
    //尾插
    void DCList_InsertTail(ElementType element);
    //头插
    void DCList_InsertHead(ElementType element);
    //尾删
    void DCList_PopBack();
    //头删
    void DCList_PopFront();
    //按下标插入
    DCList* DCList_InsertByIndex(int index, ElementType element);
    //按位删除
    void DCList_RemoveByIndex(int index);
    //查找第一个值符合的元素
    int DCList_FindFirstByElement(ElementType element, DataCompare dataCompare);
    //按值删除
    void DCList_RemoveByElement(ElementType element, DataCompare dataCompare);
    //查找下标所对应的值
    ElementType DCList_FindByIndex(int index);
    //通过下标设定值
    void DCList_SetValueByIndex(int index, ElementType element);
    //更改元素值
    void DCList_SetValueByElement(ElementType oldValue, ElementType newValue, DataCompare dataIsEqal);
    
};


#endif
